<template>
  <div class="a1">
    <div class="login-page">
      <header class="header">
        <span class="back-arrow" @click="$router.push('/PhoneLogin')">←</span>
        <span class="help">帮助</span>
      </header>
      <div class="login-form">
        <h1 class="title">请输入验证码</h1>
        <p class="agreement">
          验证码以通过断行发送至 +86 {{this.phoneNumber}}
        </p>
        <div class="input-group">
          <input type="text" class="phone-input" placeholder="请输入验证码" v-model="yzm"/>
        </div>
        <button :disabled="isLoginButtonDisabled" class="sms-button" @click="sendSmsCode">登陆</button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      phoneNumber: '',
      yzm: '',
      isPhoneNumberValid: null
    };
  },
  computed: {
    isLoginButtonDisabled() {
      return this.yzm.length !== 6;
    }
  },
  methods: {
    sendSmsCode() {
      this.axios.post("http://localhost:9000/user/login",{phone:this.phoneNumber,num:this.yzm}).then(res=>{
        if (res.data.code === 200){
          sessionStorage.setItem(res.data.data.tokenName, res.data.data.tokenValue);
          return this.$router.push("/");
        }
        alert(res.data.data)
      })
    }
  },
  created() {
    this.phoneNumber = this.$route.params.phoneNumber;
  }
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f9f9f9;
}

.login-page {
  width: 100%;
  height: 100%;
  max-width: 400px; /* 设定最大宽度 */
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  background-color: #fff;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.back-arrow {
  font-size: 24px;
  cursor: pointer;
}

.help {
  font-size: 14px;
}

.title {
  font-size: 24px;
  font-weight: bold;
  text-align: left;
  margin-bottom: 20px;
}

.agreement {
  text-align: center;
  margin: -15px 0 ;
}

.input-group {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 10px;
  margin-top: 50px;
}

.country-code{
  width: 50px;
  height: 40px;
  border: 1px solid #ccc;
  border-radius: 5px;
}
.phone-input {
  flex: 1;
  height: 40px;
  margin: 5px;
  padding: 0 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.sms-button {
  width: 100%;
  padding: 10px;
  margin: 10px 0;
  background-color: #ccc;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.sms-button:disabled {
  background-color: #eee;
}

.other-login-options {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.other-button {
  flex: 1;
  padding: 10px;
  margin: 5px;
  background-color: #f5f5f5;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.note {
  text-align: left;
  font-size: 12px;
  color: #888;
  margin-bottom: 15px;
}
</style>
